package com.gcsoftware.gateway.confLoader;

import java.util.Properties;

import com.gcsoftware.gateway.utils.NetUtils;

/**
 * Created by yinpeng on 18/1/23.
 */
public class LoadGWCfgParam
{
    private static LoadGWCfgParam ourInstance = new LoadGWCfgParam();

    public static LoadGWCfgParam getInstance()
    {
        return ourInstance;
    }
    private static final String cfgName = "gaff-dsp-gw.conf";

    private static Properties prop;

    private LoadGWCfgParam()
    {
        prop = CfgLoader.cfgLoader(cfgName);
    }

    public int getIntValue(String key, int dftVal)
    {
        if ((null == prop.getProperty(key)))
        {
            return dftVal;
        }
        else
        {
            return Integer.parseInt(prop.getProperty(key));
        }
    }

    public String getStringValue(String key, String dftVal)
    {
        return (null == prop.getProperty(key)) ? dftVal :prop.getProperty(key);
    }

    public int getAcceptor()
    {
        return getIntValue("acceptor", Runtime.getRuntime().availableProcessors());
    }

    public int getClientToProxy()
    {
        return getIntValue("clientToProxy", Runtime.getRuntime().availableProcessors()*2);
    }

    public int getProxyToServer()
    {
        return getIntValue("proxyToServer", Runtime.getRuntime().availableProcessors()*2);
    }

    public String getLocalIP()
    {
        return getStringValue("local_ip", NetUtils.getLocalHost());
    }

    public int getLocalPort()
    {
        return getIntValue("local_port", 8085);
    }

    public String getRemoteAddr()
    {
        return getStringValue("remote_addr", "");
    }
    public int getRemotePort()
    {
        return getIntValue("remote_port", 0);
    }

    public String getAuthType()
    {
        return getStringValue("auth_type", "none");
    }
    public int getMaxRequestBufferSize()
    {
        return getIntValue("max_req", 10*1024*1024);
    }

    public int getMaxResponseBufferSize()
    {
        return getIntValue("max_resp", 10*1024*1024);
    }

    public String getRemoteRedirectType(){return getStringValue("remote_redirect_type", "resolver");}

    public String getConsoleIP()
    {
        return getStringValue("console_ip", NetUtils.getLocalHost());
    }

    public int getConsolePort()
    {
        return getIntValue("console_port", 9090);
    }
}
